// import { defineStore } from 'pinia';
// import { getGoodListApi, getGoodDetailApi } from '@/service';
// import localCache from '@/utils/cache';
// const useGoodStore = defineStore('good', {
//   state: () => ({
//     goodList: [],
//     goodDetail: {},
//   }),
//   actions: {
//     async getGoodList() {
//       const res = await getGoodListApi({
//         project_id: 1,
//       });
//       this.goodList = res.result.rows;
//     },
//     async getGoodDetail(id) {
//       const res = await getGoodDetailApi(id);
//       console.log(res);
//       this.goodDetail = res.result;
//     },
//     //获取分类
//     async getClassify() {
//       const res = await getClassifyApi({
//         project_id: 2,
//         limit: 999,
//       });
//       localCache.setCache('classifyList', res.result);
//       this.classifyList = res.result;
//     },
//   },
// });
// export default useGoodStore;

import { defineStore } from 'pinia';
import { getGoodListApi, getGoodDetailApi, getClassifyApi } from '@/service';
import localCache from '@/utils/cache';
const useGoodStore = defineStore('good', {
  state: () => ({
    goodList: localCache.getCache('goodList') ?? '',
    goodDetail: localCache.getCache('goodDetail') ?? '',
    classifyList: localCache.getCache('classifyList') ?? '',
  }),
  actions: {
    //获取商品列表
    async getGoodList() {
      const res = await getGoodListApi({
        project_id: 2,
      });
      localCache.setCache('goodList', res.result.rows);
      this.goodList = res.result.rows;
    },
    //获取单个商品详情
    async getGoodDetail(id) {
      const res = await getGoodDetailApi(id);
      console.log(res);
      this.goodDetail = res.result;
      localCache.setCache('goodDetail', res.result);
      return res;
    },
    //获取分类
    async getClassify() {
      const res = await getClassifyApi({
        project_id: 2,
        limit: 999,
      });
      localCache.setCache('classifyList', res.result);
      this.classifyList = res.result;
    },
  },
});
export default useGoodStore;
